package com.example.eventlistener.listener;

import com.example.eventlistener.bean.User;
import com.example.eventlistener.event.UserEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class AnnotationListener {
    @Async
    @EventListener
    public void sendSMS(UserEvent userEvent) throws InterruptedException {
        User user = userEvent.getUser();
        System.out.println("SEND SMS");
        Thread.sleep(5000);
        System.out.println("$$$$: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
        System.out.println("Observe event happening: " + user);
    }
}
